<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}
$params = array();
array_push($params, pg_escape_string($_POST["id"]));
array_push($params, pg_escape_string($_POST["serie"]));
array_push($params, pg_escape_string($_POST["number"]));
array_push($params, pg_escape_string($_POST["supplier_id"]));
array_push($params, pg_escape_string($_POST["emission_date"]));
array_push($params, pg_escape_string($_POST["cancellation_date"]));
array_push($params, pg_escape_string($_POST["subtotal"]));
array_push($params, pg_escape_string($_POST["igv"]));
array_push($params, pg_escape_string($_POST["total"]));

$stmt = pg_prepare($connect, "update_purcharse_header", "UPDATE purcharse_header SET serie=$2,number=$3,supplier_id=$4,emission_date=$5,cancellation_date=$6,subtotal=$7,igv=$8,total=$9 WHERE id = $1 ");

$result = pg_execute($connect, "update_purcharse_header", $params);

if (!$result) {

    die("Error in SQL query: " . pg_last_error());
}

echo "Data successfully inserted!";

pg_free_result($result);
pg_close($connect);